<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog">
        <el-form :model="addBaseWageForm" ref="addBaseWageRef" :rules="addBaseWagerules">
                        <el-form-item label="人员工号" :label-width="formLabelWidth"
                                      prop="teacherNumber">
                            <el-input
                                    v-model="addBaseWageForm.teacherNumber"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写人员工号"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="人员姓名" :label-width="formLabelWidth"
                                      prop="teacherName">
                            <el-input
                                    v-model="addBaseWageForm.teacherName"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写人员姓名"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资条目id" :label-width="formLabelWidth"
                                      prop="teacherWageTypeId" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.teacherWageTypeId"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资条目id"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资条目名称" :label-width="formLabelWidth"
                                      prop="teacherWageTypeName">
                            <el-input
                                    v-model="addBaseWageForm.teacherWageTypeName"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资条目名称"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资类型id" :label-width="formLabelWidth"
                                      prop="wageType" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.wageType"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资类型id"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资类型名称" :label-width="formLabelWidth"
                                      prop="wageTypeName">
                            <el-input
                                    v-model="addBaseWageForm.wageTypeName"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资类型名称"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="是否统计" :label-width="formLabelWidth"
                                      prop="isStatistics" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.isStatistics"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写是否统计"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资钱数" :label-width="formLabelWidth"
                                      prop="wages" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.wages"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资钱数"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="校区" :label-width="formLabelWidth"
                                      prop="campus" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.campus"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写校区"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="月份" :label-width="formLabelWidth"
                                      prop="wageMonth">
                            <el-input
                                    v-model="addBaseWageForm.wageMonth"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写月份"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="工资结构1应发工资、2应扣工资" :label-width="formLabelWidth"
                                      prop="wageStructure" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.wageStructure"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写工资结构1应发工资、2应扣工资"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="uuid" :label-width="formLabelWidth"
                                      prop="uuid">
                            <el-input
                                    v-model="addBaseWageForm.uuid"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写uuid"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="创建时间" :label-width="formLabelWidth"
                                      prop="createTime" v-if="addBaseWageForm.id">
                            <el-input
                                    v-model="addBaseWageForm.createTime"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写创建时间"
                            ></el-input>
                        </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="save()">保存</el-button>
      </span>
        </template>
    </el-dialog>
</template>

<script>
    import {ref} from "vue";
    import {httpService} from "@/utils/httpService";
    import {ElMessage, ElForm} from "element-plus";
    import {vxRule} from "@/utils/validator";

    export default {
        name: "AddBaseWage",
        components: {ElForm, ElMessage},
        data() {
            return {
                dialogFormVisible: ref(false),
                formLabelWidth: "120px",
                title: "",
                personnelType: "",
                addBaseWageForm: {
                    teacherNumber: "",
                    teacherName: "",
                    teacherWageTypeId: "",
                    teacherWageTypeName: "",
                    wageType: "",
                    wageTypeName: "",
                    isStatistics: "",
                    wages: "",
                    campus: "",
                    wageMonth: "",
                    wageStructure: "",
                    uuid: "",
                    createTime: "",
                },
                // 校验规则
                addBaseWagerules: {
                    teacherNumber: vxRule(true, null, "blur"),
                    teacherName: vxRule(true, null, "blur"),
                    teacherWageTypeName: vxRule(true, null, "blur"),
                    wageTypeName: vxRule(true, null, "blur"),
                    wageMonth: vxRule(true, null, "blur"),
                    uuid: vxRule(true, null, "blur"),
                },
            };
        },
        methods: {
            closeDialog() {
                this.clear();
            },
            cancel() {
                this.dialogFormVisible = false;
                this.clear();
            },
            getBaseWageById(id) {
                httpService("/javaApi/baseWage/queryById", {id: id}, "get").then(
                    (data) => {
                        this.addBaseWageForm = data;
                    }
                );
            },
            clear() {
                this.dialogFormVisible = false;
                //清空form
                    this.addBaseWageForm.id = "";
                    this.addBaseWageForm.teacherNumber = "";
                    this.addBaseWageForm.teacherName = "";
                    this.addBaseWageForm.teacherWageTypeId = "";
                    this.addBaseWageForm.teacherWageTypeName = "";
                    this.addBaseWageForm.wageType = "";
                    this.addBaseWageForm.wageTypeName = "";
                    this.addBaseWageForm.isStatistics = "";
                    this.addBaseWageForm.wages = "";
                    this.addBaseWageForm.campus = "";
                    this.addBaseWageForm.wageMonth = "";
                    this.addBaseWageForm.wageStructure = "";
                    this.addBaseWageForm.uuid = "";
                    this.addBaseWageForm.createTime = "";
            },
            save() {
                this.$refs.addBaseWageRef.validate((valid) => {
                    if (valid) {
                        let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                        params.append("teacherNumber", this.addBaseWageForm.teacherNumber);
                        params.append("teacherName", this.addBaseWageForm.teacherName);
                        params.append("teacherWageTypeId", this.addBaseWageForm.teacherWageTypeId);
                        params.append("teacherWageTypeName", this.addBaseWageForm.teacherWageTypeName);
                        params.append("wageType", this.addBaseWageForm.wageType);
                        params.append("wageTypeName", this.addBaseWageForm.wageTypeName);
                        params.append("isStatistics", this.addBaseWageForm.isStatistics);
                        params.append("wages", this.addBaseWageForm.wages);
                        params.append("campus", this.addBaseWageForm.campus);
                        params.append("wageMonth", this.addBaseWageForm.wageMonth);
                        params.append("wageStructure", this.addBaseWageForm.wageStructure);
                        params.append("uuid", this.addBaseWageForm.uuid);
                        params.append("createTime", this.addBaseWageForm.createTime);
                        if (this.addBaseWageForm.id) {
                            params.append("id", this.addBaseWageForm.id);
                            httpService("/javaApi/baseWage/edit", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("修改成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getBaseWageList();
                                    } else {
                                        ElMessage.error("修改失败");
                                    }
                                }
                            );
                        } else {
                            httpService("/javaApi/baseWage/add", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("添加成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getBaseWageList();
                                    } else {
                                        ElMessage.error("添加失败");
                                    }
                                }
                            );
                        }
                    } else {
                        return false;
                    }
                });
            },
        },
    };
</script>
<style>
</style>